import sys
import os
import threading
import queue
from PyQt6.QtWidgets import (
    QApplication, QMainWindow, QPushButton, QFileDialog, QComboBox, QVBoxLayout,
    QWidget, QLabel, QListWidget, QProgressBar, QHBoxLayout, QSizePolicy
)
import edge_tts
import asyncio
import pygame
from PyQt6.QtGui import QFont, QMovie
from PyQt6.QtCore import Qt, QTimer
import subprocess
import uuid
import json

def split_text_by_length(text, max_len=300):
    sentences = [s.strip() for s in text.replace('\n', '').split('。') if s.strip()]
    segments = []
    current = ""
    for s in sentences:
        s_full = s + "。"
        if len(current) + len(s_full) <= max_len:
            current += s_full
        else:
            if current:
                segments.append(current)
            current = s_full
    if current:
        segments.append(current)
    return segments

LANG_VOICE = {
    "中文": "zh-CN-XiaoxiaoNeural",
    "日文": "ja-JP-NanamiNeural",
    "英语": "en-US-JennyNeural"
}

from PyQt6.QtWidgets import QApplication
from ui import TTSPlayer
import sys

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = TTSPlayer()
    win.show()
    sys.exit(app.exec())
